系統CentOS安裝:
網上很多教程,很詳細,我就不再贅述了。在安裝過程中,需要注意的是設置時區、個人賬戶密碼、root密碼(一定要注意,否則后續很麻煩)、在首次啟動時,需要接受許可。
NETCoreSDK安裝:
安裝nginx:
我是按照下面的方式安裝的:
# 1、下載對應當前系統版本的nginx包(package),具體版本根據自己情況http://nginx.org/packages/ wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm # 2、建立nginx的yum倉庫 rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm # 3、下載並安裝nginx yum install nginx # 4、啟動nginx服務 systemctl start nginx # 或者 service nginx start命令也可以
5、配置
默認的配置文件在 /etc/nginx 路徑下,使用該配置已經可以正確地運行nginx;如需要自定義,修改其下的 nginx.conf 等文件即可。
6、測試
在瀏覽器地址欄中輸入部署nginx環境的機器的IP,如果一切正常,應該能看到如下字樣的內容。
==============
配置Nginx.conf,代理,位於etc/nginx/nginx.conf文件,主要是設置了server節點中的一些東西。別的東西還沒動,如果涉及到多站點部署的話,一些配置還是需要修改的。
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /var/log/nginx/access.log main; sendfile on; #tcp_nopush on; keepalive_timeout 65; #gzip on; #如果是多站點配置,需要啟用這個配置,然后在conf.d文件夾下,創建多個配置文件即可。比如www.a.com.conf、www.b.com.conf #include /etc/nginx/conf.d/*.conf; server { listen 80; #root /usr/share/nginx/html; #index index.html index.htm; # Make site accessible from http://localhost/ server_name hwapp.netcore.cn; location / { proxy_pass http://localhost:5000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection keep-alive; proxy_set_header Host $host; proxy_cache_bypass $http_upgrade; proxy_set_header X-Real-IP $remote_addr; proxy_set_header REMOTE-HOST $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } }
配置好上面的nginx.conf后,檢查一下是否正確。
[root@localhost /]# whereis nginx nginx: /usr/sbin/nginx /etc/nginx /usr/share/nginx /usr/share/man/man3/nginx.3pm.gz /usr/share/man/man8/nginx.8.gz
# 檢測配置是否有問題 [root@localhost /]# /usr/sbin/nginx -t nginx: [emerg] invalid URL prefix in /etc/nginx/nginx.conf:49 nginx: configuration file /etc/nginx/nginx.conf test failed [root@localhost /]# /usr/sbin/nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful
#重啟nginx服務, [root@localhost /]# sudo service nginx restart Redirecting to /bin/systemctl restart nginx.service [root@localhost /]# #或者使用reload [root@localhost /]# /usr/sbin/nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful [root@localhost /]# sudo nginx -s reload [root@localhost /]#
遇到的問題:
2016/07/19 22:00:02 [crit] 60088#60088: *24 connect() to 127.0.0.1:5000 failed (13: Permission denied) while connecting to upstream, client: 192.168.74.129, server: localhost, request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "192.168.74.129"
經過一番檢查搜索,應該是SeLinux的導致的。可以選擇一些兩種方式進行:
1、關閉SeLinux,可以查看以下文章:
CentOS下查看SeLinux狀態及關閉SeLinux:http://www.hpboys.com/824.html
2、執行下面的命令(我執行的是這個)
setsebool -P httpd_can_network_connect 1
項目發布:
參考各個命令使用以及runtimes的平台配置 http://www.cnblogs.com/shanyou/archive/2016/07/04/5636920.html
進入項目目錄(跟project.json同級),然后執行命令
dotnet publish -r centos.7-x64
dotnet publish -r centos.7-x64比如:我發布到CentOS7上,dotnet publish -r centos.7-x64
會在\bin\Debug\netcoreapp1.0中生成publish文件夾,然后把整個文件夾copy到CentOS 你指定的文件夾就可以了。比如我的是/opt/DotNetCorePublish/DotNetCoreDemo1/publish
[hager@localhost publish]$ dotnet HelloWebApp.dll Hosting environment: Production Content root path: /opt/DotNetCorePublish/HelloWebApp/publish Now listening on: http://localhost:5000 Application started. Press Ctrl+C to shut down.
注意事項
dotnet run HelloWebApp.dllhttp://www.cnblogs.com/linezero/p/aspnetcoreubuntu.html
# 我的虛擬機IP,以及nginx配置的代理
192.168.74.129 hwapp.netcore.cn
目前需要解決的問題是:(后續解決后,再補充,或者重新寫新的筆記)
1、nginx開啟啟動 ----》 systemctl enable nginx.service 即可 2017-09-06 add
2、netcore項目自運行 ---》安裝supervisor 守護進程即可 2017-09-06 add
參考資料: