上周架设了一个简单的服务器,流程如下:
1.安装并更新apt;
2.使用apt-get安装nginx,mysql,php及相关拓展;
3.nginx服务器配置文件默认位置: /etc/nginx/sites-available/
4.nginx默认root位置: /usr/share/nginx/html
5.nginx默认网站根目录: /var/www
6.nginx服务器配置:
sudo vim /etc/nginx/sites-available/default
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;
}
}
- 其中root,index ,server_name和location这几行需要稍微修改一下,
- root:代表网站的目录,
- index:表示Nginx的访问首页,
- server_name:表示服务器的公网IP或域名.
7.最后修改如下:
server {
listen 80 default_server;
listen [::]:80 default_server ipv6only=on;
root /var/www/separes/public;
index index.php index.html index.htm;
server_name xxx.xx.xx.xxx;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
try_files $uri /index.php =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;
}
}
8.重启nginx试运行;
网友评论