Justin's Words

Nginx restore in Ubuntu

起因是在 Nginx 下打开任何一个 .php 都 403,Laravel 设置 app/storage 为 777 访问 /public 同样 403,于是决定 restore Nginx

环境

Ubuntu 14.10 Nginx Version: 1.6.2

完全卸载 Nginx

1
$ sudo apt-get purge nginx nginx-core nginx-common nginx-full

卸载完成后可以重启下服务器

重装 Nginx

1
$ sudo apt-get install nginx

配置 Nginx

1
$ sudo vim /etc/nginx/sites-avaiable/default

看到的默认配置如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

root /usr/share/nginx/html;
index index.html index.htm;

server_name localhost;

location / {
try_files $uri $uri/ =404;
}
}

我们需要做点修改:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;

root /usr/share/nginx/html;
index index.php index.html index.htm;

server_name server_domain_name_or_IP;

location / {
try_files $uri $uri/ =404;
}

error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

修改完成后,保存文件,重启 Nginx

1
$ sudo service nginx restart

至此问题解决。