此配置 需要先進阿里雲官網,再進入 萬網里面進行解析域名,再用Nginx命令進行配置,,,如果沒有申請端口號,則要先去申請了再進行解析
一、申請端口號。
1.進入阿里雲=>進入實例=>管理實例=>安全組規則=>右上角 添加安全組規則(尋找一個常用的端口,添加一個即可比如說 88 端口,,添加頁面 端口范圍填:88/88,授權對象填:0.0.0.0/0)
2.添加完之后 進入萬網解析那里,點擊解析 ,,然后再添加解析(主機記錄填寫你要的二級域名,記錄值填公網IP),然后就可以了,,主機記錄里面不用寫.com或啥子www之類的,直接寫名字
二,進入Xshell進行命令語句添加進行配置Nginx
首先要建一個目錄,上傳項目的位置
1.建一個文件夾在www下面,與html同級
# cd /
# cd /var/www =>選擇 www文件
# ll =>列出www文件夾里面的內容
# ls
# mkdir youbao =>進行添加的文件名字 youbao
# ls
現在你可以去查看www下面新增了youbao這個文件夾,然后把項目在上傳進去!!!!!!然后進行連接數據庫,,,更改項目內數據庫的配置,服務器地址為公網IP以及密碼,,,然后接下來在進行更改Nginx文件
# find / -name nginx.conf => 尋找conf文件
# vim /etc/nginx/nginx.conf =>進入conf文件以備修改
進去之后 要按一下e這個鍵,(溫馨提示:不要按enter鍵)
文件server里面寫 88為你添加的端口號,server_name 的youbao為你的二級域名,,root里面為為上線項目的文件夾位置,然后保存退出 :wq
server {
listen 88;
server_name youbao.benecess.com;
charset utf-8;
#access_log logs/host.access.log main;
root /var/www/youbao/public;
index index.html index.htm index.php;
location / {
if (!-e $request_filename) {
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location ~ \.php$ {
fastcgi_pass unix:/dev/shm/php-cgi.sock;
fastcgi_index index.php;
include fastcgi_params;
set $real_script_name $fastcgi_script_name;
if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
set $real_script_name $1;
set $path_info $2;
}
fastcgi_param SCRIPT_FILENAME $document_root$real_script_name;
fastcgi_param SCRIPT_NAME $real_script_name;
fastcgi_param PATH_INFO $path_info;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|flv|ico)$ {
expires 30d;
access_log off;
}
location ~ .*\.(js|css)?$ {
expires 7d;
access_log off;
}
}
2.然后去尋找conf
# find / -name tourism.benecess.com.conf
# cd tourism.benecess.com.conf youbao.benecess.com.conf
# cd /usr/local/nginx/conf/vhost
# cp tourism.benecess.com.conf youbao.benecess.com.conf => cp 為復制
# vim youbao.benecess.com.conf =>進去把東西都改成你自己的 比如說域名 文件夾位置
server {
listen 80;
server_name tourism.benecess.com;
access_log /data/wwwlogs/tourism.benecess.com_nginx.log combined;
index index.html index.htm index.php;
root /var/www/html/public;
if ($host != tourism.benecess.com) { return 301 $scheme://tourism.benecess.com$request_uri; }
include /usr/local/nginx/conf/rewrite/none.conf;
#error_page 404 /404.html;
#error_page 502 /502.html;
server {
listen 80;
server_name tourism.benecess.com;
access_log /data/wwwlogs/tourism.benecess.com_nginx.log combined;
index index.html index.htm index.php;
root /var/www/html/public;
if ($host != tourism.benecess.com) { return 301 $scheme://tourism.benecess.com$request_uri; }
include /usr/local/nginx/conf/rewrite/none.conf;
#error_page 404 /404.html;
#error_page 502 /502.html;
location / {
root /var/www/html/public;
index index.html index.php;
if ( -f $request_filename) {
break;
}
if ( !-e $request_filename) {
rewrite ^(.*)$ /index.php/$1 last;
break;
}
}
# service nginx restart => 重啟Nginx
然后就可以直接訪問了!!!大功告成
如果頁面報這個錯
則是此項目沒有權限的問題( chmod 千萬別寫錯了哦 )
# chmod -R 777 /var/www/youbao/runtime
給了權限之后 就可以應用了,,,,給自己點個贊!!!希望能幫到大家,若有錯誤請評論..........